apiready = function () {
  api.parseTapmode();
  FastClick.attach(document.body);
  var header = $api.byId('aui-header');
  $api.fixStatusBar(header);
  $(".conditions-fixed").css("margin-top",api.safeArea.top);
  var pageContentH=$(".conditions-fixed").height()+10;
  $(".page-content").css("padding-top",pageContentH);
  $(".page-content").css("padding-bottom",pageContentH);
  var conditions_list_fixed_h =  $("#aui-header").height()+$(".conditions-fixed").height();
  $(".conditions-list-fixed").css("top",conditions_list_fixed_h);
 app.pager("#pageOrder",function(){
     pageOrder.loadlist();
 });
 api.setRefreshHeaderInfo({
     loadingImg: 'widget://image/refresh.png',
     bgColor: '#fdd903',
     textColor: '#fff',
     textDown: '下拉刷新...',
     textUp: '松开刷新...'
 }, function(ret, err) {
    pageOrder.loadlist(1);
 });

  var pageOrder = new Vue({
      el: '#pageOrder',
      data: {
          moneyLog:[],
          reload:0,
          lastpage:0,
          page:1,
          type:'',
          addtime:-1,
          paystatus:-1,
          order_type:-1,
          conditions:[],
          conditionsList:[],
          chooseConditions:{},
          nodata:0
      },
      created: function() {
         this.loadlist();
         this.loadcondition();
      },
     methods: {
       loadcondition:function(){
         var that = this;
         app.get("apiv2/order/getOrderCondition", {
            },function(res){

           if (res.code != 200) {
             app.alert(res.msg);
             return;
           }
           that.conditions =  res.data;
         })
       },
       setCondition:function(key,value){
         var chooseConditions = this.chooseConditions;
         var type = this.type;
         chooseConditions[type] = value;
         this.chooseConditions = chooseConditions;
         this[type] = key;
         this.loadlist(1);
         this.type='';
         console.log(this[type]);
       },
       showCondtion:function(type){
         this.type = type;
         this.conditionsList = this.conditions[type];
       },
       //资金流水
          loadlist:function(reload){
            var that = this;
            if (reload==1){
              this.loading =0;
              this.page =1;
              this.lastpage =0;
              this.moneyLog =[];
            }
            if (this.loading==1 || this.lastpage==1){
              return ;
            }
            var page = this.page;
            this.loading=1;
            // 'order_sn','shop','addtime','pay_time','status','store_id','user_id','paytype','suceess_url','title','body','order_type','done','order_amount','goods_amount','yie','trade_no','notify','discounts','commission','updatetime','data','deduct_yie','appid','card_code','consume_card_code','shop_id','sub_order','paystatus','payStatusText','user.avatarUrl'
            var condition = {
              page: page,
              limit:10,
              order:'addtime desc',
              order_type:'all',
              fields:'order_sn,addtime,pay_time,status,paytype,title,order_type,order_amount,trade_no,paystatus,payStatusText,user.avatarUrl,paytypeText,orderTypeText'
            };
            if(this.order_type!=-1){
              condition.order_type = this.order_type;
            }
            if(this.addtime!=-1){
              condition.addtime = this.addtime;
            }
            if(this.paystatus!=-1){
              condition.paystatus = this.paystatus;
            }
            app.get("apiv2/order/get", condition ,function(res){
              api.refreshHeaderLoadDone();
              that.loading = 0;
              if (res.code != 200) {
                app.alert(res.msg);
                return;
              }
              if (res.data.list.length==0){
                that.lastpage=1;
              }
              that.page++;
              that.moneyLog =  that.moneyLog.concat(res.data.list);
              if(that.moneyLog.length==0){
                that.nodata=1;
              }else{
                that.nodata=0;
              }

            })
          },
          // 查看订单详情
          order_detail:function(order_type,order_sn){
            // 'payonline'=>'收钱码',
            // shopping'=>'在线下单',
            // orderOffline'=>'餐桌码',
            // book'=>'在线预约',
            // recharge'=>'预充值'

            if(order_type=="shopping"){
              webView("https://wap.bestsmartbee.com/apps/oms?store_id={store_id}#/orderDetail/"+order_sn);
            }else if(order_type=='orderOffline'){
              webView("https://wap.bestsmartbee.com/apps/oms?store_id={store_id}#/eatInHallOrder/"+order_sn);
            }else if(order_type=='book'){
              webView("https://wap.bestsmartbee.com/apps/oms?store_id={store_id}#/bookDetail/"+order_sn);
            }else{
              openFrame("orderDetail","./orderDetail.html",0,{order_sn:order_sn});
            }
          }

     }
  })
}
